# coding: utf8
# try something like
# customize for your setup
database = db.t_repositories

def index(): return dict(message="hello from uc_config.py")

def error():
    return dict()

@auth.requires_login()
def create():
    form=crud.create(database,next='read/[id]')
    return dict(form=form)

@auth.requires_login()
def read():
    record = database(request.args(0)) or redirect(URL('error'))
    form=crud.read(database,record)
    return dict(form=form)

@auth.requires_login()
def update():
    record = database(request.args(0),active=True) or redirect(URL('error'))
    form=crud.update(database,record,next='read/[id]',
                     ondelete=lambda form: redirect(URL('select')),
                     onaccept=crud.archive)
    return dict(form=form)

@auth.requires_login()
def select():
    f,v=request.args(0),request.args(1)
    try: query=f and database[f]==v or database
    except: redirect(URL('error'))
    rows=db(query)(database.active==True).select()
    return dict(rows=rows)

@auth.requires_login()
def search():
    form, rows=crud.search(database,query=database.active==True)
    return dict(form=form, rows=rows)
